laydate.render({
    elem: '#search_daterange',
    range: true,
});
$(".search_btn").on("click", function () {
    var unit = $("#unit").val();
    var title = $("#title").val();
    var formData = $('.search-form').serializeArray();
    //搜索条件对象
    var search = new Object();
    var isValid = true;

    $.each(formData, function (k, v) {
        var val;
        //将name切割为字段和搜索条件
        var name_arr = v['name'].split("-");
        if (name_arr[1] == 'between') {
            if(search[name_arr[0]]){
                if(!v['value']) {
                    notice.error('请输入'+ title +'最大值');
                    isValid = false;
                    return false;
                }
                max_val = parseInt(v['value']) * unit;
                if(max_val < parseInt(search[name_arr[0]].v)) {
                    notice.error(title +'最大值不能小于最小值');
                    isValid = false;
                    return false;
                }
                search[name_arr[0]].v.push(max_val);
            } else {
                if(v['value']) {
                    val = [parseInt(v['value']) * unit];
                }
            }
        } else {
            val = v['value'];
        }
        if(val) {
            //将数据封装为value值对象，格式为{k: '搜索条件',v: '数值'}
            var data = new Object();
            data.k = name_arr[1];
            data.v = val;
            //将key值封装为字段名
            search[name_arr[0]] = data;
        }
    });

    if (!isValid) return false;

    table.reload('dataTable', {
        page: {
            curr: 1 //重新从第 1 页开始
        },
        where: {
            search: search
        }
    })
});
$(".clean_btn").on("click", function () {
    $("#search_daterange").val('');
    $(".searchVal").val('');
    $(".betweenVal").val('');
    $(".search_select").val('');
    $(".search_select").val('');
    layui.form.render('select');

    var formData = $('.search-form').serializeArray();
    //搜索条件对象
    var search = new Object();
    $.each(formData, function (k, v) {
        //将name切割为字段和搜索条件
        var name_arr = v['name'].split("-");
        //将数据封装为value值对象，格式为{k: '搜索条件',v: '数值'}
        var data = new Object();
        data.k = name_arr[1];
        data.v = v['value'];
        //将key值封装为字段名
        search[name_arr[0]] = data;
    });

    table.reload('dataTable', {
        page: {
            curr: 1 //重新从第 1 页开始
        },
        where: {
            search: search
        }
    })
});
